package neusoft.edu.cn.guanshangshiguang.model;

import java.util.List;

import neusoft.edu.cn.guanshangshiguang.Listener.ListListener;
import neusoft.edu.cn.guanshangshiguang.bean.CommentOnlineBean;
import neusoft.edu.cn.guanshangshiguang.bean.CommentSchoolBean;
import neusoft.edu.cn.guanshangshiguang.common.Common;
import neusoft.edu.cn.guanshangshiguang.service.Service;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class CommentSchoolModel {

    private Retrofit retrofit;

    public CommentSchoolModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl("http://"+ Common.IpAddress+"/literature_museum/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getResultList(String school_bid,final ListListener BookListListener){

        Service bookDetailsService = retrofit.create(Service.class);

        Call<List<CommentSchoolBean>> onlineBookListBeanCall = bookDetailsService.getBorrowSchoolCommentList(school_bid);

        onlineBookListBeanCall.enqueue(new Callback<List<CommentSchoolBean>>() {
                @Override
                public void onResponse(Call<List<CommentSchoolBean>> call, Response<List<CommentSchoolBean>> response) {
                    if(response!=null)
                        BookListListener.onResponse(response.body());
                    else BookListListener.onFail("获取个人创作列表失败");
                }

            @Override
            public void onFailure(Call<List<CommentSchoolBean>> call, Throwable t) {
                BookListListener.onFail(t.toString());
            }
        });
    }
}
